package conf

import (
	"fmt"
	"github.com/roseboy/goo"
	"github.com/roseboy/goo/demo/web"
)

type AppConfig struct{}

func (config *AppConfig) ConfigConstant(cfg *goo.Config) {
	cfg.SetStaticPath("./demo/static/")
}

func (config *AppConfig) ConfigPlugin() {
	panic("implement me")
}

func (config *AppConfig) ConfigInterceptor() {
	panic("implement me")
}

func (config *AppConfig) AfterStart() {
	fmt.Println("==>启动完成")
}

func (config *AppConfig) ConfigRoute(routes *goo.Routes) {
	routes.Intercept(func(invocation *goo.Invocation) {
		fmt.Println("global interceptor before")
		invocation.Invoke()
		fmt.Println("global interceptor after")
	})
	routes.Add("api_v1/demo/", &web.DemoController{}).Intercept(Interceptor)
	routes.Get("api_v1/demo2/index/", web.Demo2Index)
	routes.Post("api_v1/demo2/hello/", web.Demo2Hello)

	routes.Add("open", &web.OpenController{})
}

func Interceptor(inv *goo.Invocation) {
	fmt.Println("config interceptor before")
	inv.Invoke()
	fmt.Println("config interceptor after")
}
